package com.young.common.client.log.core;

import com.young.interfaces.log.model.LogDTO;
import com.young.common.util.LogUtil;
import org.aspectj.lang.JoinPoint;

/**
 * 日志抓捕任务,用于异步格式化日志信息(将请求信息封装为LogDTO)
 * Created by rookie on 2017/11/10.
 */
public class LogCatchTask implements Runnable {

    private JoinPoint joinPoint;//方法切入点对象
    private LogDTO logDTO;//日志

    /**
     * 无参构造器
     */
    public LogCatchTask(){
        super();
    }

    /**
     * 带参构造器
     * @param joinPoint
     * @param logDTO
     */
    public LogCatchTask(JoinPoint joinPoint, LogDTO logDTO){
        super();
        this.joinPoint = joinPoint;
        this.logDTO = logDTO;
    }
    @Override
    public void run() {
        if (logDTO.getEndTime() != null && logDTO.getBeginTime() != null) {
            logDTO.setMs(logDTO.getEndTime().getTime() - logDTO.getBeginTime().getTime());//方法耗时
        }
        logDTO.setServerIp(LogUtil.getLocalIp());//服务器ip

        //放入日志队列
        LogControl.put(logDTO);
    }

    public JoinPoint getJoinPoint() {
        return joinPoint;
    }

    public void setJoinPoint(JoinPoint joinPoint) {
        this.joinPoint = joinPoint;
    }

    public LogDTO getLogDTO() {
        return logDTO;
    }

    public void setLogDTO(LogDTO logDTO) {
        this.logDTO = logDTO;
    }
}
